package com.develop.skwen.electricgomall.category;

import android.support.v7.widget.RecyclerView;
import android.widget.RelativeLayout;

import com.develop.skwen.basemodule.list.BaseItemClickListener;
import com.develop.skwen.basemodule.util.StatusBarUtil;
import com.develop.skwen.basemodule.view.BaseView;
import com.develop.skwen.electricgomall.R;
import com.develop.skwen.electricgomall.category.itemList.CategoryItemListAdapter;
import com.develop.skwen.electricgomall.category.list.CategoryListAdapter;
import com.develop.skwen.electricgomall.category.model.CategoryBean;
import com.develop.skwen.electricgomall.category.model.CategoryItemBean;

/**
 * Created by skwen
 * on 18-5-29
 */

public class CategoryView extends BaseView<CategoryContract.CategoryPresenter> implements CategoryContract.CategoryVu {


    private RecyclerView mCategoryList;

    private RecyclerView mCategoryItemList;

    private RelativeLayout mToolBarLayout;


    @Override
    protected int getLayoutRes() {
        return R.layout.category_layout;
    }

    @Override
    protected void initViews() {
        mToolBarLayout = findViewById(R.id.toolbar_layout);
        mCategoryList = findViewById(R.id.category_list);
        mCategoryItemList = findViewById(R.id.category_item_list);
        setMargins(mToolBarLayout,0, StatusBarUtil.getStatusBarHeight(getActivity()),0,0);
    }

    @Override
    public void setCategoryListAdapter(final CategoryListAdapter categoryListAdapter) {
        mCategoryList.setLayoutManager(getPresenter().getLayoutManager());
        mCategoryList.setAdapter(categoryListAdapter);
        categoryListAdapter.setOnBaseItemClickListener(new BaseItemClickListener<CategoryBean>() {
            @Override
            public void onItemClickListener(int position, CategoryBean categoryBean) {
                categoryListAdapter.setSelectPosition(position);
                getPresenter().getCategoryBeanData(categoryBean);
            }
        });
    }

    @Override
    public void setCategoryItemListAdapter(CategoryItemListAdapter categoryItemListAdapter) {
        mCategoryItemList.setLayoutManager(getPresenter().getGridLayoutManager());
        mCategoryItemList.setAdapter(categoryItemListAdapter);
        categoryItemListAdapter.setOnBaseItemClickListener(new BaseItemClickListener<CategoryItemBean>() {
            @Override
            public void onItemClickListener(int position, CategoryItemBean categoryItemBean) {
                getPresenter().getCategoryItemBeanData(categoryItemBean);
            }
        });
    }
}
